How to convert List<int> to string[]?

Posted by George Edison on Stack Overflow See other posts from Stack Overflow or by George Edison
Published on 2010-12-23T04:23:22Z Indexed on 2010/12/23 4:54 UTC
Read the original article Hit count: 228

Filed under:
|
|
|

I need an easy way to convert a List<int> to a string array.

I have:

var the_list = new List<int>();
the_list.Add(1);
the_list.Add(2);
the_list.Add(3);

string[] the_array = new string[the_list.Count];
for(var i = 0 ; i < the_array.Count; ++i)
    the_array[i] = the_list[i].ToString();

...which looks to be very ugly to me.

Is there an easier way?


Note: I'm looking for an easier way - not necessarily a faster way.

© Stack Overflow or respective owner

Related posts about c#

Related posts about arrays